<?php

namespace App\Kuafu\Customer\Service;

use App\Kuafu\Common\Service\CommonService;
use App\Kuafu\Customer\Enum\CustomerCodeEnum;
use App\Kuafu\Customer\Model\CustomerModel;
use App\Kuafu\Customer\Exceptions\CustomerException;
use App\Kuafu\Base\Service\BaseService;
use App\Kuafu\CustomerCoupon\Exceptions\CustomerCouponException;
use App\Kuafu\CustomerCoupon\Model\CustomerSendCouponLogModel;

class CustomerSendCouponLogService extends BaseService
{
    public static function addData($data)
    {
        try {
            CustomerSendCouponLogModel::query()->create($data);
        } catch (\Exception $exception) {
            throw new CustomerException(CustomerCodeEnum::ERR_SEND_COUPON);
        }
    }

    public static function checkIsSend($userId, $type): bool
    {
        $obj = CustomerSendCouponLogModel::query()
                                         ->where(['userId' => $userId, 'activityType' => $type])
                                         ->first();
        if ($obj) {
            return true;
        } else {
            return false;
        }
    }
}
